package com.ruoyi.web.controller.pc;


import com.ruoyi.business.domain.WmsTransfer;
import com.ruoyi.business.service.IWmsTransferService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.ISysUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 调拨管理Controller
 *
 * @author ruoyi
 * @date 2023-12-24
 */
@RestController
@RequestMapping("/business/transfer")
public class WmsTransferController extends BaseController {

    @Autowired
    private IWmsTransferService wmsTransferService;

    @Autowired
    private ISysUserService sysUserService;

    /**
     * @Description: 列表
     * @author yunlong
     */
    @ApiOperation(value = "列表")
    @GetMapping("list")
    @CrossOrigin
    public TableDataInfo queryList(WmsTransfer info) {
        startPage();
        List<WmsTransfer> list = wmsTransferService.selectWmsTransferList(info);
        return getDataTable(list);
    }

    @GetMapping("query")
    @CrossOrigin
    public AjaxResult query(WmsTransfer info) {
        List<WmsTransfer> list = wmsTransferService.selectWmsTransferList(info);
        return AjaxResult.success(list);
    }

    @GetMapping("queryAll")
    @CrossOrigin
    public AjaxResult queryAll() {
        WmsTransfer info = new WmsTransfer();
        info.setInStatus(5);
        List<WmsTransfer> list = wmsTransferService.selectWmsTransferList(info);
        return AjaxResult.success(list);
    }

    /**
     * 新增
     */
    @Log(title = "新增", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WmsTransfer info)
    {
        SysUser sysUser = sysUserService.selectUserById(getUserId());
        info.setStatus(1);
        info.setCreateBy(sysUser.getNickName());
        info.setOutStatus(0);
        info.setInStatus(0);
        return toAjax(wmsTransferService.insertWmsTransfer(info));
    }

    /**
     * 编辑
     */
    @Log(title = "编辑", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody WmsTransfer info)
    {
        return toAjax(wmsTransferService.updateWmsTransfer(info));
    }

    /**
     * @Description: 详情接口
     * @author yunlong
     */
    @ApiOperation(value = "详情接口")
    @GetMapping("getDetail")
    @CrossOrigin
    public AjaxResult getDetail(WmsTransfer info) {
        info = wmsTransferService.selectWmsTransferList(info).get(0);
        return AjaxResult.success(info);
    }
}
